#include "rewrite/synit.h"
#include "util/util.h"
#include "util/usage.h"
#include "base/cktname.h"

int main( int argc , const char ** argv )
{
   ArgAnalyzer arg( "do <ckt:aig> [-o <ckt:aig>] [-rewrite] [-refactor] [-balance] [-b] [-inv] [-db <dbname:db>]" , argc , argv );
   Usage usg;

   StrashAIG c9;
   CktName names;

   if( arg["-rewrite"].setted ) 
   {
      InfoCut c0;
      c0.read_aig( arg[0].c_str() , & names );c0.init();

      if( arg["-db"].setted )
      {
         RewriteDB db;
         db.read_DB( arg["-db"][0] );
         if( arg["-b"].setted ) rewriteb( db, c0 , c9 );
         else                   rewrite ( db, c0 , c9 );      
      }
      else                    
      {
         if( arg["-b"].setted ) rewriteb( c0 , c9 );
         else                   rewrite ( c0 , c9 );      
      }
   }
   else if( arg["-refactor"].setted )
   {
      Refactor c0;
      c0.read_aig( arg[0].c_str() , & names);c0.init();

      if( arg["-inv"].setted ) refactor( c0 , c9 );
      else                     refactor_inv( c0 , c9 );
   }
   else if( arg["-balance"].setted )
   {
      Balance c0;
      c0.read_aig( arg[0].c_str() , & names);c0.init();

      balance( c0 , c9 );
   }
   else
   {
      InfoCut c0;
      c0.read_aig( arg[0].c_str() , & names );c0.init();

      synit( c0 , c9 );
   }

   report(c9);
   if( arg["-o"].setted ){ c9.write_aig( arg["-o"][0] ,&names);}
   usg.report();
}
